package com.fantastic.web.ex;

import com.fantastic.common.exception.CheckException;
import com.fantastic.common.exception.DataCheckException;
import com.fantastic.common.exception.FileTypeException;
import com.fantastic.common.result.ResultData;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author: rxx
 * @since: 2024/5/22 16:08
 * @description: 数据相关的异常
 */
//标明为控制全局异常处理器
@ControllerAdvice
//标明为响应体
@ResponseBody
public class DataExceptionAdvice {

    /**
     * 文件类型不支持异常
     *
     * @return 返回状态对象
     * @ExceptionHandler() 标明controller层只要有方法抛出这个异常就会进入到个方法对异常进行处理
     * @ResponseBody 返回响应体，自动json
     */
    @ExceptionHandler(FileTypeException.class)
    public ResultData loginExceptionMethod(FileTypeException e) {
        return new ResultData(e.getResponseStatusEnum());
    }

    /**
     * 数据类型不规范异常
     *
     * @return 返回状态对象
     */
    @ExceptionHandler(DataCheckException.class)
    public ResultData registerExceptionMethod(DataCheckException e) {
        return new ResultData(e.getResponseStatusEnum());
    }

    /**
     * 数据检查异常
     *
     * @return 返回状态对象
     */
    @ExceptionHandler(CheckException.class)
    public ResultData checkExceptionMethod(CheckException e) {
        return new ResultData(e.getResponseStatusEnum());
    }


}
